﻿using System.Windows;
using System.Windows.Forms;

namespace Workbench.Presentation
{
    public partial class NewProjectDialog : Window
    {
        public NewProjectDialogViewModel ViewModel = new NewProjectDialogViewModel();
        public NewProjectDialog()
        {
            InitializeComponent();
            this.DataContext = ViewModel;
        }

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            if (!ViewModel.ProjectDbPath.EndsWith("wbdb"))
            {
                ViewModel.ProjectDbPath = string.Format("{0}.wbdb", ViewModel.ProjectDbPath);
            }
            this.Close();
        }

        private void BrowseButton_Click(object sender, RoutedEventArgs e)
        {
            var sfd = new SaveFileDialog()
            {
                Filter = "Workbench DB (*.wbdb)|*.wbdb",
                ValidateNames = true,
                Title = "New Project",
                SupportMultiDottedExtensions = true,
                OverwritePrompt = true,
                CheckPathExists = true,
                FileName = ViewModel.ProjectName
            };
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                ViewModel.ProjectDbPath = sfd.FileName;
            }
        }
    }
}
